/***********************************************************************
filename: 	hgeRect.h
created:	8/3/2004
author:		Paul D Turner

purpose:	Defines 'hgeRect' class
*************************************************************************/

#ifndef _HgeRect_h_
#define _HgeRect_h_

#include "hgeForwardRef.h"
#include "hgeVector.h"
#include "hgeEnums.h"

/*!
\brief
Class encapsulating operations on a hgeRectangle
*/
class hgeRect
{
public:
	hgeRect(void) {bClean = true;}
	hgeRect(float left, float top, float right, float bottom);
	hgeRect(Point pos, Size sz);


	Point	getPosition(void) const		{return Point(d_left, d_top);}
	float	getWidth(void) const		{return d_right - d_left;}
	float	getHeight(void) const		{return d_bottom - d_top;}
	Size	getSize(void) const			{return Size(getWidth(), getHeight());}
	void	setPosition(const Point& pt);
	void	setWidth(float width)		{d_right = d_left + width;}
	void	setHeight(float height)		{d_bottom = d_top + height;}
	void	setSize(const Size& sze)	{setWidth(sze.d_x); setHeight(sze.d_y);}


	// return a hgeRect that is the intersection of 'this' hgeRect with the hgeRect 'hgeRect'
	hgeRect	getIntersection(const hgeRect& rect) const;

	//Applies an offset the hgeRect object
	hgeRect&	offset(const Point& pt);

	//Return true if the given Point falls within this hgeRect
	bool	isPointInRect(const Point& pt) const;
	bool	isPointInRect(float x, float y) const;

	//check the size of the hgeRect object and if it is bigger than \a sz, resize it so it isn't.
	hgeRect&	constrainSizeMax(const Size& sz);

	//check the size of the hgeRect object and if it is smaller than \a sz, resize it so it isn't.
	hgeRect&	constrainSizeMin(const Size& sz);

	//check the size of the hgeRect object and if it is bigger than \a max_sz or smaller than \a min_sz, resize it so it isn't.
	hgeRect&	constrainSize(const Size& max_sz, const Size& min_sz);

	/*************************************************************************
	Operators
	*************************************************************************/
	bool	operator==(const hgeRect& rhs) const
	{
		return ((d_left == rhs.d_left) && (d_right == rhs.d_right) && (d_top == rhs.d_top) && (d_bottom == rhs.d_bottom));
	}

	bool	operator!=(const hgeRect& rhs) const		{return !operator==(rhs);}

	hgeRect&	operator=(const hgeRect& rhs);

	hgeRect operator*(float scalar) const      { return hgeRect(d_left * scalar, d_top * scalar, d_right * scalar, d_bottom * scalar); }
	const hgeRect& operator*=(float scalar)    { d_left *= scalar; d_top *= scalar; d_right *= scalar; d_bottom *= scalar; return *this; }
	
	void	Clear()	{bClean = true;}
	void	SetRadius(float x, float y, float r) { d_top = x - r; d_right = x + r; d_top = y - r; d_bottom = y + r;}
	void	Encapsulate(float x, float y);
	bool	isIntersect(const hgeRect& rect) const;
	void	Set(float left, float top, float right, float bottom) {d_top = top, d_bottom = bottom, d_left = left, d_right = right;}

	/*************************************************************************
	Data Fields
	*************************************************************************/
	float	d_top, d_bottom, d_left, d_right;
	bool	bClean;
};

#endif	// end of guard _HgeRect_h_
